﻿Public Class NetworkDrives
    Private Function setPrefix(ByVal size As Long) As String
        Dim TotalString As String = ""
        For Prefix As Integer = 0 To 4
            If size < 1024 Or Prefix = 4 Then
                TotalString = size
                Select Case Prefix
                    Case 0
                        TotalString &= "B"
                    Case 1
                        TotalString &= "KB"
                    Case 2
                        TotalString &= "MB"
                    Case 3
                        TotalString &= "GB"
                    Case 4
                        TotalString &= "TB"
                End Select
                Exit For
            Else
                size /= 1024
            End If
        Next
        Return TotalString
    End Function

    Private Sub NetworkDrives_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        For Each Drive In My.Computer.FileSystem.Drives
            Dim DriveInfo As String = Drive.Name & " (" & Drive.DriveType.ToString & ") "
            If Drive.IsReady = True Then
                DriveInfo &= setPrefix(Drive.TotalSize - Drive.TotalFreeSpace) & "/" & setPrefix(Drive.TotalSize)
            Else
                DriveInfo &= "Not available"
            End If
            lstDrivers.Items.Add(DriveInfo)
        Next
    End Sub
End Class